package com.xbx.baseweb.controller;

import com.xbx.baseweb.constant.ResponseCode;
import com.xbx.baseweb.model.ResponseModel;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

public abstract class BaseController {

	public ResponseModel successResponse() {
		return successResponse(null);
	}
	
	public ResponseModel successResponse(Map<String, Object> model) {
		ResponseModel ResponseModel = new ResponseModel();
		ResponseModel.setCode(ResponseCode.SUCCESS.getCode());
		ResponseModel.setMsg("success");
		ResponseModel.setData(model);
		return ResponseModel;
	}

	public ResponseModel successResponse(Map<String, Object> model, String msg) {
		ResponseModel ResponseModel = new ResponseModel();
		ResponseModel.setCode(ResponseCode.SUCCESS.getCode());
		ResponseModel.setMsg(msg);
		ResponseModel.setData(model);
		return ResponseModel;
	}

	public ResponseModel failResponse(ResponseCode errorCode) {
		return failResponse(errorCode, errorCode.getMessage());
	}

	public ResponseModel failResponse(ResponseCode errorCode, String message) {
		ResponseModel ResponseModel = new ResponseModel();
		ResponseModel.setCode(errorCode.getCode());
		ResponseModel.setMsg(message);
		return ResponseModel;
	}

	public ResponseModel failResponse(int code, String message) {
		ResponseModel ResponseModel = new ResponseModel();
		ResponseModel.setCode(code);
		ResponseModel.setMsg(message);
		return ResponseModel;
	}

	public ModelAndView createMav(String viewName, Map<String, ?> model) {
		return new ModelAndView(viewName, model);
	}
}
